#!/usr/bin/perl

# mkd
# File ID: f695a960-5d3f-11df-ab55-90e6ba3022ac
# Konverterer datoer til dbk-link.

$| = 1;

if ($ARGV[0] =~ /^\d{8}$/) {
	my $arg_date = $ARGV[0];
	my @stdin_data = <STDIN>;
	printf("<a href=\"../%s/%s.html\">", substr($arg_date, 0, 4), $arg_date);
	print foreach(@stdin_data);
	print("</a>");
	exit;
}

while (<>) {
	s!([12]\d\d\d)([/\-])(\d\d)([/\-])(\d\d)!<a href="../$1/$1$3$5.html">$1$2$3$4$5</a>!g;
	s!([12]\d\d\d)(\d\d)(\d\d)(T\d+)(Z?)!<a href="../$1/$1$2$3.html">$1$2$3$4$5</a>!g;
	print;
}
